function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var t = e(require("./event-emitter")), a = e(require("./api-code")), i = e(require("./socket")), r = e(require("./api")), n = {
    app: "card"
};

exports.default = {
    app: n.app,
    initial: function(e) {
        var t = this;
        return Object.assign(n, e), new Promise(function(e) {
            t.loadUnreadsNum().then(e), i.default.on(i.default.EVENT_TYPES.MESSAGE_CHAT, t.loadMsg);
        });
    },
    loadMsg: function(e) {
        var a = e.params;
        +a.issystemchat || (+a.issystem || t.default.emit("unreads.syn", {
            type: "add",
            num: 1
        }), t.default.emit("radar.message.socket", a));
    },
    loadUnreadsNum: function() {
        return r.default.chat.message.unreads().then(function(e) {
            var a = e.data.count;
            getApp().globalData.radarCount = a, t.default.emit("radar.unreads.change", {
                count: a
            });
        });
    },
    checkExistCorp: function(e, t) {
        var a = this;
        if (e && e.cardid) return r.default.market.corp.existmember(t).then(function(t) {
            var i = t.data, r = i.isexist, n = i.issubscribe, o = i.mobile;
            return r || a.marketJoin(e), a.checkNeedReplaceMobile(e, r, n, o), {
                isexist: r,
                issubscribe: n,
                mobile: o
            };
        });
    },
    marketJoin: function(e) {
        var t = this;
        return r.default.market.corp.join({
            data: {
                cardid: e.cardid
            }
        }).then(function(e) {
            return e.code !== a.default.PARAM_MISSING || (t.verifyMobile(), !1);
        });
    },
    verifyMobile: function() {
        wx.showModal({
            content: "请完成名片手机号验证",
            confirmText: "去认证",
            success: function(e) {
                e.confirm && wx.navigateTo({
                    url: "/pages/changemobile/changemobile"
                });
            }
        });
    },
    checkNeedReplaceMobile: function(e, t, a, i) {
        a || !t || t && +i == +e.mobile || this.replaceMobileModel(e, i);
    },
    replaceMobileModel: function(e, t) {
        var a = this;
        wx.showModal({
            title: "你已加入商务雷达",
            content: "将关注手机更新为: " + e.mobile + "\n或继续使用原手机: " + t,
            confirmText: "更新手机",
            cancelText: "不更换",
            success: function(t) {
                return a.replaceMobile(e, t.confirm);
            }
        });
    },
    replaceMobile: function(e, t) {
        r.default.market.corp.replacemobile({
            data: {
                cardid: e.cardid,
                op: t ? "replace" : "notreplace"
            }
        }).then(function() {
            wx.showToast({
                title: "提交成功",
                duration: 500
            });
        });
    }
};